package com.whisper.utils;

import java.awt.Graphics;
import javax.swing.*;
import javax.swing.plaf.basic.BasicTextFieldUI;

public class ZTextField extends JTextField {

    private int arcSize;

    public ZTextField(int columns, int arcSize) {
        super(columns);
        this.arcSize = arcSize;
        setUI(new RoundTextFieldUI());
    }

    public int getArcSize() {
        return arcSize;
    }

    public void setArcSize(int arcSize) {
        this.arcSize = arcSize;
        repaint();
    }

    private class RoundTextFieldUI extends BasicTextFieldUI {

        @Override
        protected void installDefaults() {
            super.installDefaults();
            LookAndFeel.installBorder(getComponent(), "TextField.border");
        }

        @Override
        protected void paintBackground(Graphics g) {
            g.setColor(getComponent().getBackground());
            g.fillRoundRect(0, 0, getComponent().getWidth() - 1, getComponent().getHeight() - 1, arcSize, arcSize);
        }
    }
}